import React, { useDebugValue, useState } from 'react'

const useLocalstorage = (name, Lvalue = '') => {
    const getL = () => {
        const data = localStorage.getItem(name)
        return data !== null ? data : Lvalue
    }
    const [l, setL] = useState(getL)
    const updataL = (newValue) => {
        localStorage.setItem(name, newValue)
        setL(newValue)
    }
    const delL = () => {
        localStorage.removeItem(name)
        setL(Lvalue)
    }
    useDebugValue(l, (value) => {
        return '格式化：' + value
    })
    return [l, updataL, delL]
}
export default function Udebug() {
    const [l, updataL, delL] = useLocalstorage('xxx', 'value')
    return (
        <>
            <div>{l}</div>
            <button onClick={() => updataL('张三')}>更新</button>
            <button onClick={() => delL()}>删除</button>
        </>
    )
}
